﻿using System.Collections.Generic;
using UnityEngine;

public abstract class ISoldier : ICharacter
{
    protected SoldierFSMSystem mFSMSystem;

    public ISoldier() : base()
    {
        MakeFSM();
    }

    public override void UnderAttack(int damage)
    {
        base.UnderAttack(damage);
        if (mAttr.CurrentHp <= 0)
        {
            PlaySound();
            PlayEffect();
            Killed();
        }
    }

    protected abstract void PlaySound();

    protected abstract void PlayEffect();

    public override void UpdateFSMAI(List<ICharacter> targets)
    {
        mFSMSystem.CurrState.Reasoning(targets);
        mFSMSystem.CurrState.Actioning(targets);
    }

    private void MakeFSM()
    {
        mFSMSystem = new SoldierFSMSystem();

        SoldierIdleState soldierIdleState = new SoldierIdleState(mFSMSystem, this);
        soldierIdleState.AddTransition(SoldierTransition.SeeEnemy, SoldierStateId.Chase);

        SoldierChaseState soldierChaseState = new SoldierChaseState(mFSMSystem, this);
        soldierChaseState.AddTransition(SoldierTransition.NoEnemy, SoldierStateId.Idel);
        soldierChaseState.AddTransition(SoldierTransition.CanAttack, SoldierStateId.Attack);

        SoldierAttackState soldierAttackState = new SoldierAttackState(mFSMSystem, this);
        soldierAttackState.AddTransition(SoldierTransition.NoEnemy, SoldierStateId.Idel);
        soldierAttackState.AddTransition(SoldierTransition.SeeEnemy, SoldierStateId.Chase);

        mFSMSystem.AddState(soldierIdleState, soldierChaseState, soldierAttackState);
    }
}